# 使用大模型寻找新工作地点
import json

#import LLM


def list_sort(elem):
    return elem.get('times')


def get_new_work_location(rider_info, pickup_merchant: list, now_location, positive_reviews_num, negative_reviews_num):
    if not pickup_merchant:
        info = {"has_pickup_merchant": False}
    else:
        pickup_merchant.sort(key=list_sort, reverse=True)
        info = {"has_pickup_merchant": True, "pickup_merchant": pickup_merchant}
    info["now_location"] = now_location
    info["positive_reviews_num"] = positive_reviews_num
    info["negative_reviews_num"] = negative_reviews_num
    info["sex"] = rider_info['sex']
    info["diligent_level"] = rider_info['diligent_level']
    # 2表示是要询问自己应该转移去哪里
    try:
        response = json.loads(LLM.get_response_from_llm(2, info))
        # print(response.get('coordinate'))
        return response.get('coordinate')
    except Exception:
        print("")
        return now_location


if __name__ == "__main__":
    # test
    pickup_merchant = [{'times': 12, 'location': (26, 92)}, {'times': 11, 'location': (91, 59)}, {'times': 10, 'location': (53, 98)}, {'times': 10, 'location': (39, 103)}, {'times': 5, 'location': (26, 99)}]
   # pickup_merchant = []
    now_location = [182, 33]
    rider_info = {'sex': 1, "diligent_level": 1}
    get_new_work_location(rider_info, pickup_merchant, now_location,10,0)
